source("../../lib/som-utils.R")
Attaching package: 'dplyr'
The following objects are masked from 'package:stats':
filter, lag
The following objects are masked from 'package:base':
intersect, setdiff, setequal, union
source("../../lib/maps-utils.R")
Linking to GEOS 3.8.0, GDAL 3.0.4, PROJ 6.3.1
mpr.set_base_path_analysis()
model <- mpr.load_model("som-137.rds.xz")
summary(model)
SOM of size 5x5 with a hexagonal topology and a bubble neighbourhood function.
The number of data layers is 1.
Distance measure(s) used: sumofsquares.
Training data included: 156652 objects.
Mean distance to the closest unit in the map: 1.227.
plot(model, type="changes")
df <- mpr.load_data("datos_semana_2k.csv.xz")
df
summary(df)
id_estacion fecha fecha_cnt tmax
Length:156652 Length:156652 Min. : 1.00 Min. :-109.0
Class :character Class :character 1st Qu.:13.00 1st Qu.: 147.0
Mode :character Mode :character Median :27.00 Median : 201.0
Mean :26.53 Mean : 202.1
3rd Qu.:40.00 3rd Qu.: 262.0
Max. :53.00 Max. : 442.0
tmin precip nevada prof_nieve
Min. :-189.00 Min. : 0.00 Min. :0 Min. : 0.000
1st Qu.: 48.00 1st Qu.: 0.00 1st Qu.:0 1st Qu.: 0.000
Median : 98.00 Median : 3.00 Median :0 Median : 0.000
Mean : 98.13 Mean : 16.92 Mean :0 Mean : 0.604
3rd Qu.: 152.00 3rd Qu.: 20.00 3rd Qu.:0 3rd Qu.: 0.000
Max. : 272.00 Max. :690.00 Max. :0 Max. :1073.000
longitud latitud altitud
Min. :27.82 Min. :-17.889 Min. : 1.0
1st Qu.:39.01 1st Qu.: -4.850 1st Qu.: 44.0
Median :41.22 Median : -1.411 Median : 263.0
Mean :40.05 Mean : -2.426 Mean : 478.5
3rd Qu.:42.19 3rd Qu.: 1.272 3rd Qu.: 687.0
Max. :43.57 Max. : 4.216 Max. :2535.0
world <- ne_countries(scale = "medium", returnclass = "sf")
spain <- subset(world, admin == "Spain")
plot(model, type="count", shape = "straight", palette.name = mpr.degrade.bleu)
NĂºmero de elementos en cada celda:
nb <- table(model$unit.classif)
print(nb)
1 2 3 4 5 6 7 8 9 10 11 12 13
1120 5161 6409 7482 3008 8641 6344 10804 7674 1298 7701 8299 3942
14 15 16 17 18 19 20 21 22 23 24 25
4317 933 13215 9828 6971 6927 3389 6621 4704 4241 8076 9547
ComprobaciĂ³n de nodos vacĂos:
dim_model <- 5*5;
len_nb = length(nb);
empty_nodes <- dim_model != len_nb;
if (empty_nodes) {
print(paste("[Warning] Existen nodos vacĂos: ", len_nb, "/", dim_model))
}
plot(model, type="dist.neighbours", shape = "straight")
model_colnames = c("fecha_cnt", "tmax", "tmin", "precip", "longitud", "latitud", "altitud")
model_ncol = length(model_colnames)
plot(model, shape = "straight")
par(mfrow=c(3,4))
for (j in 1:model_ncol) {
plot(model, type="property", property=getCodes(model,1)[,j],
palette.name=mpr.coolBlueHotRed,
main=model_colnames[j],
cex=0.5, shape = "straight")
}
if (!empty_nodes) {
cor <- apply(getCodes(model,1), 2, mpr.weighted.correlation, w=nb, som=model)
print(cor)
}
fecha_cnt tmax tmin precip longitud latitud
[1,] 0.08432857 -0.7469848 -0.7842133 0.41799419 0.4894182 0.2265599
[2,] 0.89786174 0.3009610 0.2987476 -0.02755607 0.2177896 0.2643051
altitud
[1,] 0.32418276
[2,] -0.03335556
RepresentaciĂ³n de cada variable en un mapa de factores:
if (!empty_nodes) {
par(mfrow=c(1,1))
plot(cor[1,], cor[2,], xlim=c(-1,1), ylim=c(-1,1), type="n")
lines(c(-1,1),c(0,0))
lines(c(0,0),c(-1,1))
text(cor[1,], cor[2,], labels=model_colnames, cex=0.75)
symbols(0,0,circles=1,inches=F,add=T)
}
Importancia de cada variable - varianza ponderada por el tamaño de la celda:
if (!empty_nodes) {
sigma2 <- sqrt(apply(getCodes(model,1),2,function(x,effectif)
{m<-sum(effectif*(x-weighted.mean(x,effectif))^2)/(sum(effectif)-1)},
effectif=nb))
print(sort(sigma2,decreasing=T))
}
longitud altitud tmax latitud fecha_cnt tmin precip
0.9451666 0.9283950 0.9045293 0.9042700 0.9010965 0.8970326 0.8632285
if (!empty_nodes) {
hac <- mpr.hac(model, nb)
}
if (!empty_nodes) {
plot(hac, hang=-1, labels=F)
rect.hclust(hac, k=3)
}
A quĂ© clĂºster pertenece cada nodo del mapa de kohonen:
if (!empty_nodes) {
groups <- cutree(hac, k=3)
plot(model, type="mapping",
bgcol=c("steelblue1","sienna1","yellowgreen","red","blue","yellow","purple","green","white","#1f77b4", '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2')[groups],
shape = "straight", labels = "")
add.cluster.boundaries(model, clustering=groups)
}
if (!empty_nodes) {
# Asignamos a cada registro su clĂºster
df$cluster <- groups[model$unit.classif]
}
Nuevos dataframes por cluster
if (!empty_nodes) {
# Creo nuevos dataframes, uno por cada clĂºster.
df.cluster01 <- subset(df, cluster==1)
df.cluster02 <- subset(df, cluster==2)
df.cluster03 <- subset(df, cluster==3)
# Extraigo del dataframe las features.
df.cluster01 <- select(df.cluster01, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster02 <- select(df.cluster02, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster03 <- select(df.cluster03, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
}
if (!empty_nodes) summary(df.cluster01)
fecha_cnt tmax tmin precip nevada
Min. : 1.00 Min. : -3.0 Min. :-51.0 Min. : 0.000 Min. :0
1st Qu.:13.00 1st Qu.:211.0 1st Qu.:149.0 1st Qu.: 0.000 1st Qu.:0
Median :26.00 Median :234.0 Median :172.0 Median : 0.000 Median :0
Mean :26.29 Mean :229.6 Mean :165.2 Mean : 5.422 Mean :0
3rd Qu.:39.00 3rd Qu.:262.0 3rd Qu.:201.0 3rd Qu.: 2.000 3rd Qu.:0
Max. :53.00 Max. :384.0 Max. :263.0 Max. :167.000 Max. :0
prof_nieve longitud latitud altitud
Min. :0 Min. :27.82 Min. :-17.89 Min. : 14.0
1st Qu.:0 1st Qu.:28.05 1st Qu.:-16.56 1st Qu.: 25.0
Median :0 Median :28.44 Median :-16.33 Median : 33.0
Mean :0 Mean :28.35 Mean :-16.03 Mean : 369.5
3rd Qu.:0 3rd Qu.:28.48 3rd Qu.:-15.39 3rd Qu.: 64.0
Max. :0 Max. :28.95 Max. :-13.60 Max. :2371.0
if (!empty_nodes) summary(df.cluster02)
fecha_cnt tmax tmin precip nevada
Min. : 1.00 Min. :-31.0 Min. :-161.00 Min. : 0.00 Min. :0
1st Qu.:14.00 1st Qu.:152.0 1st Qu.: 52.00 1st Qu.: 0.00 1st Qu.:0
Median :27.00 Median :203.0 Median : 99.00 Median : 3.00 Median :0
Mean :26.54 Mean :208.5 Mean : 99.39 Mean : 16.63 Mean :0
3rd Qu.:40.00 3rd Qu.:267.0 3rd Qu.: 148.00 3rd Qu.: 20.00 3rd Qu.:0
Max. :53.00 Max. :442.0 Max. : 272.00 Max. :690.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.0000 Min. :27.82 Min. :-17.889 Min. : 1.0
1st Qu.: 0.0000 1st Qu.:39.56 1st Qu.: -4.488 1st Qu.: 52.0
Median : 0.0000 Median :41.29 Median : -1.293 Median : 258.0
Mean : 0.0815 Mean :40.73 Mean : -1.677 Mean : 374.5
3rd Qu.: 0.0000 3rd Qu.:42.12 3rd Qu.: 1.296 3rd Qu.: 639.0
Max. :685.0000 Max. :43.57 Max. : 4.216 Max. :2535.0
if (!empty_nodes) summary(df.cluster03)
fecha_cnt tmax tmin precip
Min. : 1.00 Min. :-109.00 Min. :-189.000 Min. : 0.00
1st Qu.:13.00 1st Qu.: 26.00 1st Qu.: -36.000 1st Qu.: 4.00
Median :26.00 Median : 70.00 Median : 5.000 Median : 21.00
Mean :26.51 Mean : 74.19 Mean : 6.032 Mean : 33.88
3rd Qu.:41.00 3rd Qu.: 124.00 3rd Qu.: 52.000 3rd Qu.: 49.00
Max. :53.00 Max. : 232.00 Max. : 148.000 Max. :256.00
nevada prof_nieve longitud latitud
Min. :0 Min. : 0.000 Min. :28.31 Min. :-16.4992
1st Qu.:0 1st Qu.: 0.000 1st Qu.:42.18 1st Qu.: 0.7789
Median :0 Median : 0.000 Median :42.47 Median : 1.2717
Mean :0 Mean : 9.254 Mean :42.29 Mean : 0.8465
3rd Qu.:0 3rd Qu.: 0.000 3rd Qu.:42.64 3rd Qu.: 1.7150
Max. :0 Max. :1073.000 Max. :42.77 Max. : 2.4378
altitud
Min. : 953
1st Qu.:1971
Median :2247
Mean :2187
3rd Qu.:2400
Max. :2535
if (!empty_nodes) {
df.clusters.dim <- c(dim(df.cluster01)[1], dim(df.cluster02)[1], dim(df.cluster03)[1])
barplot(df.clusters.dim,
names.arg = c("cluster01", "cluster02", "cluster03"),
col = "steelblue1")
}
if (!empty_nodes) mpr.hist(df.cluster01)
if (!empty_nodes) mpr.hist(df.cluster02)
if (!empty_nodes) mpr.hist(df.cluster03)
if (!empty_nodes) mpr.boxplot(df.cluster01)
if (!empty_nodes) mpr.boxplot(df.cluster02)
if (!empty_nodes) mpr.boxplot(df.cluster03)
# Agrupa por longitud y latitud para rellenar el mapa con menos datos.
if (!empty_nodes) {
df.cluster01.grouped <- mpr.group_by_geo(df.cluster01)
df.cluster02.grouped <- mpr.group_by_geo(df.cluster02)
df.cluster03.grouped <- mpr.group_by_geo(df.cluster03)
}
if (!empty_nodes) mpr.draw_map(spain, df.cluster01.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster02.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster03.grouped)
if (!empty_nodes) {
plot(hac, hang=-1, labels=F)
rect.hclust(hac, k=4)
}
A quĂ© clĂºster pertenece cada nodo del mapa de kohonen:
if (!empty_nodes) {
groups <- cutree(hac, k=4)
plot(model, type="mapping",
bgcol=c("steelblue1","sienna1","yellowgreen","red","blue","yellow","purple","green","white","#1f77b4", '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2')[groups],
shape = "straight", labels = "")
add.cluster.boundaries(model, clustering=groups)
}
if (!empty_nodes) {
# Asignamos a cada registro su clĂºster
df$cluster <- groups[model$unit.classif]
}
Nuevos dataframes por cluster
if (!empty_nodes) {
# Creo nuevos dataframes, uno por cada clĂºster.
df.cluster01 <- subset(df, cluster==1)
df.cluster02 <- subset(df, cluster==2)
df.cluster03 <- subset(df, cluster==3)
df.cluster04 <- subset(df, cluster==4)
# Extraigo del dataframe las features.
df.cluster01 <- select(df.cluster01, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster02 <- select(df.cluster02, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster03 <- select(df.cluster03, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster04 <- select(df.cluster04, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
}
if (!empty_nodes) summary(df.cluster01)
fecha_cnt tmax tmin precip nevada
Min. : 1.00 Min. : -3.0 Min. :-51.0 Min. : 0.000 Min. :0
1st Qu.:13.00 1st Qu.:211.0 1st Qu.:149.0 1st Qu.: 0.000 1st Qu.:0
Median :26.00 Median :234.0 Median :172.0 Median : 0.000 Median :0
Mean :26.29 Mean :229.6 Mean :165.2 Mean : 5.422 Mean :0
3rd Qu.:39.00 3rd Qu.:262.0 3rd Qu.:201.0 3rd Qu.: 2.000 3rd Qu.:0
Max. :53.00 Max. :384.0 Max. :263.0 Max. :167.000 Max. :0
prof_nieve longitud latitud altitud
Min. :0 Min. :27.82 Min. :-17.89 Min. : 14.0
1st Qu.:0 1st Qu.:28.05 1st Qu.:-16.56 1st Qu.: 25.0
Median :0 Median :28.44 Median :-16.33 Median : 33.0
Mean :0 Mean :28.35 Mean :-16.03 Mean : 369.5
3rd Qu.:0 3rd Qu.:28.48 3rd Qu.:-15.39 3rd Qu.: 64.0
Max. :0 Max. :28.95 Max. :-13.60 Max. :2371.0
if (!empty_nodes) summary(df.cluster02)
fecha_cnt tmax tmin precip nevada
Min. : 1.00 Min. :-31.0 Min. :-161.00 Min. : 0.00 Min. :0
1st Qu.:14.00 1st Qu.:153.0 1st Qu.: 52.00 1st Qu.: 0.00 1st Qu.:0
Median :27.00 Median :204.0 Median : 99.00 Median : 3.00 Median :0
Mean :26.51 Mean :208.8 Mean : 99.46 Mean : 15.16 Mean :0
3rd Qu.:39.00 3rd Qu.:267.0 3rd Qu.: 149.00 3rd Qu.: 19.00 3rd Qu.:0
Max. :53.00 Max. :442.0 Max. : 272.00 Max. :172.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :28.46 Min. :-16.329 Min. : 1.0
1st Qu.: 0.00000 1st Qu.:39.56 1st Qu.: -4.488 1st Qu.: 52.0
Median : 0.00000 Median :41.29 Median : -1.293 Median : 258.0
Mean : 0.06592 Mean :40.73 Mean : -1.668 Mean : 374.2
3rd Qu.: 0.00000 3rd Qu.:42.11 3rd Qu.: 1.296 3rd Qu.: 639.0
Max. :299.00000 Max. :43.57 Max. : 4.216 Max. :2143.0
if (!empty_nodes) summary(df.cluster03)
fecha_cnt tmax tmin precip
Min. : 1.00 Min. :-109.00 Min. :-189.000 Min. : 0.00
1st Qu.:13.00 1st Qu.: 26.00 1st Qu.: -36.000 1st Qu.: 4.00
Median :26.00 Median : 70.00 Median : 5.000 Median : 21.00
Mean :26.51 Mean : 74.19 Mean : 6.032 Mean : 33.88
3rd Qu.:41.00 3rd Qu.: 124.00 3rd Qu.: 52.000 3rd Qu.: 49.00
Max. :53.00 Max. : 232.00 Max. : 148.000 Max. :256.00
nevada prof_nieve longitud latitud
Min. :0 Min. : 0.000 Min. :28.31 Min. :-16.4992
1st Qu.:0 1st Qu.: 0.000 1st Qu.:42.18 1st Qu.: 0.7789
Median :0 Median : 0.000 Median :42.47 Median : 1.2717
Mean :0 Mean : 9.254 Mean :42.29 Mean : 0.8465
3rd Qu.:0 3rd Qu.: 0.000 3rd Qu.:42.64 3rd Qu.: 1.7150
Max. :0 Max. :1073.000 Max. :42.77 Max. : 2.4378
altitud
Min. : 953
1st Qu.:1971
Median :2247
Mean :2187
3rd Qu.:2400
Max. :2535
if (!empty_nodes) summary(df.cluster04)
fecha_cnt tmax tmin precip nevada
Min. : 1.00 Min. :-21.0 Min. :-68.00 Min. :159.0 Min. :0
1st Qu.:13.00 1st Qu.:122.0 1st Qu.: 61.00 1st Qu.:183.0 1st Qu.:0
Median :41.00 Median :154.0 Median : 91.00 Median :208.0 Median :0
Mean :30.84 Mean :155.3 Mean : 88.98 Mean :232.1 Mean :0
3rd Qu.:45.00 3rd Qu.:190.0 3rd Qu.:119.00 3rd Qu.:255.0 3rd Qu.:0
Max. :53.00 Max. :331.0 Max. :226.00 Max. :690.0 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.000 Min. :27.82 Min. :-17.889 Min. : 1.0
1st Qu.: 0.000 1st Qu.:40.78 1st Qu.: -7.456 1st Qu.: 44.0
Median : 0.000 Median :42.08 Median : -1.787 Median : 251.0
Mean : 2.375 Mean :40.91 Mean : -2.938 Mean : 416.9
3rd Qu.: 0.000 3rd Qu.:42.64 3rd Qu.: 1.331 3rd Qu.: 445.0
Max. :685.000 Max. :43.57 Max. : 4.216 Max. :2535.0
if (!empty_nodes) {
df.clusters.dim <- c(dim(df.cluster01)[1], dim(df.cluster02)[1], dim(df.cluster03)[1], dim(df.cluster04)[1])
barplot(df.clusters.dim,
names.arg = c("cluster01", "cluster02", "cluster03", "cluster04"),
col = "steelblue1")
}
if (!empty_nodes) mpr.hist(df.cluster01)
if (!empty_nodes) mpr.hist(df.cluster02)
if (!empty_nodes) mpr.hist(df.cluster03)
if (!empty_nodes) mpr.hist(df.cluster04)
if (!empty_nodes) mpr.boxplot(df.cluster01)
if (!empty_nodes) mpr.boxplot(df.cluster02)
if (!empty_nodes) mpr.boxplot(df.cluster03)
if (!empty_nodes) mpr.boxplot(df.cluster04)
# Agrupa por longitud y latitud para rellenar el mapa con menos datos.
if (!empty_nodes) {
df.cluster01.grouped <- mpr.group_by_geo(df.cluster01)
df.cluster02.grouped <- mpr.group_by_geo(df.cluster02)
df.cluster03.grouped <- mpr.group_by_geo(df.cluster03)
df.cluster04.grouped <- mpr.group_by_geo(df.cluster04)
}
if (!empty_nodes) mpr.draw_map(spain, df.cluster01.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster02.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster03.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster04.grouped)
if (!empty_nodes) {
plot(hac, hang=-1, labels=F)
rect.hclust(hac, k=5)
}
A quĂ© clĂºster pertenece cada nodo del mapa de kohonen:
if (!empty_nodes) {
groups <- cutree(hac, k=5)
plot(model, type="mapping",
bgcol=c("steelblue1","sienna1","yellowgreen","red","blue","yellow","purple","green","white","#1f77b4", '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2')[groups],
shape = "straight", labels = "")
add.cluster.boundaries(model, clustering=groups)
}
if (!empty_nodes) {
# Asignamos a cada registro su clĂºster
df$cluster <- groups[model$unit.classif]
}
Nuevos dataframes por cluster
if (!empty_nodes) {
# Creo nuevos dataframes, uno por cada clĂºster.
df.cluster01 <- subset(df, cluster==1)
df.cluster02 <- subset(df, cluster==2)
df.cluster03 <- subset(df, cluster==3)
df.cluster04 <- subset(df, cluster==4)
df.cluster05 <- subset(df, cluster==5)
# Extraigo del dataframe las features.
df.cluster01 <- select(df.cluster01, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster02 <- select(df.cluster02, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster03 <- select(df.cluster03, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster04 <- select(df.cluster04, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster05 <- select(df.cluster05, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
}
if (!empty_nodes) summary(df.cluster01)
fecha_cnt tmax tmin precip nevada
Min. : 1.00 Min. : -3.0 Min. :-51.0 Min. : 0.000 Min. :0
1st Qu.:13.00 1st Qu.:211.0 1st Qu.:149.0 1st Qu.: 0.000 1st Qu.:0
Median :26.00 Median :234.0 Median :172.0 Median : 0.000 Median :0
Mean :26.29 Mean :229.6 Mean :165.2 Mean : 5.422 Mean :0
3rd Qu.:39.00 3rd Qu.:262.0 3rd Qu.:201.0 3rd Qu.: 2.000 3rd Qu.:0
Max. :53.00 Max. :384.0 Max. :263.0 Max. :167.000 Max. :0
prof_nieve longitud latitud altitud
Min. :0 Min. :27.82 Min. :-17.89 Min. : 14.0
1st Qu.:0 1st Qu.:28.05 1st Qu.:-16.56 1st Qu.: 25.0
Median :0 Median :28.44 Median :-16.33 Median : 33.0
Mean :0 Mean :28.35 Mean :-16.03 Mean : 369.5
3rd Qu.:0 3rd Qu.:28.48 3rd Qu.:-15.39 3rd Qu.: 64.0
Max. :0 Max. :28.95 Max. :-13.60 Max. :2371.0
if (!empty_nodes) summary(df.cluster02)
fecha_cnt tmax tmin precip nevada
Min. : 1.00 Min. :-31.0 Min. :-161.00 Min. : 0.00 Min. :0
1st Qu.: 9.00 1st Qu.:134.0 1st Qu.: 34.00 1st Qu.: 0.00 1st Qu.:0
Median :18.00 Median :170.0 Median : 69.00 Median : 7.00 Median :0
Mean :23.84 Mean :172.2 Mean : 67.73 Mean : 19.92 Mean :0
3rd Qu.:43.00 3rd Qu.:210.0 3rd Qu.: 102.00 3rd Qu.: 28.00 3rd Qu.:0
Max. :53.00 Max. :407.0 Max. : 247.00 Max. :172.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :28.46 Min. :-16.329 Min. : 1.0
1st Qu.: 0.00000 1st Qu.:40.07 1st Qu.: -3.919 1st Qu.: 68.6
Median : 0.00000 Median :41.38 Median : -1.169 Median : 353.0
Mean : 0.09678 Mean :40.86 Mean : -1.476 Mean : 423.8
3rd Qu.: 0.00000 3rd Qu.:42.14 3rd Qu.: 1.401 3rd Qu.: 704.0
Max. :299.00000 Max. :43.57 Max. : 4.216 Max. :2143.0
if (!empty_nodes) summary(df.cluster03)
fecha_cnt tmax tmin precip
Min. : 1.00 Min. :-109.00 Min. :-189.000 Min. : 0.00
1st Qu.:13.00 1st Qu.: 26.00 1st Qu.: -36.000 1st Qu.: 4.00
Median :26.00 Median : 70.00 Median : 5.000 Median : 21.00
Mean :26.51 Mean : 74.19 Mean : 6.032 Mean : 33.88
3rd Qu.:41.00 3rd Qu.: 124.00 3rd Qu.: 52.000 3rd Qu.: 49.00
Max. :53.00 Max. : 232.00 Max. : 148.000 Max. :256.00
nevada prof_nieve longitud latitud
Min. :0 Min. : 0.000 Min. :28.31 Min. :-16.4992
1st Qu.:0 1st Qu.: 0.000 1st Qu.:42.18 1st Qu.: 0.7789
Median :0 Median : 0.000 Median :42.47 Median : 1.2717
Mean :0 Mean : 9.254 Mean :42.29 Mean : 0.8465
3rd Qu.:0 3rd Qu.: 0.000 3rd Qu.:42.64 3rd Qu.: 1.7150
Max. :0 Max. :1073.000 Max. :42.77 Max. : 2.4378
altitud
Min. : 953
1st Qu.:1971
Median :2247
Mean :2187
3rd Qu.:2400
Max. :2535
if (!empty_nodes) summary(df.cluster04)
fecha_cnt tmax tmin precip nevada
Min. :13.0 Min. :129.0 Min. : 27.0 Min. : 0.0 Min. :0
1st Qu.:27.0 1st Qu.:256.0 1st Qu.:140.0 1st Qu.: 0.0 1st Qu.:0
Median :32.0 Median :289.0 Median :166.0 Median : 0.0 Median :0
Mean :32.1 Mean :285.4 Mean :165.8 Mean : 5.2 Mean :0
3rd Qu.:37.0 3rd Qu.:316.0 3rd Qu.:192.0 3rd Qu.: 6.0 3rd Qu.:0
Max. :52.0 Max. :442.0 Max. :272.0 Max. :71.0 Max. :0
prof_nieve longitud latitud altitud
Min. :0.000000 Min. :35.28 Min. :-8.6239 Min. : 1.0
1st Qu.:0.000000 1st Qu.:38.95 1st Qu.:-5.3456 1st Qu.: 35.0
Median :0.000000 Median :41.10 Median :-1.8606 Median : 127.0
Mean :0.001355 Mean :40.48 Mean :-2.0703 Mean : 270.5
3rd Qu.:0.000000 3rd Qu.:41.99 3rd Qu.: 0.8856 3rd Qu.: 513.0
Max. :7.000000 Max. :43.57 Max. : 4.2156 Max. :1167.0
if (!empty_nodes) summary(df.cluster05)
fecha_cnt tmax tmin precip nevada
Min. : 1.00 Min. :-21.0 Min. :-68.00 Min. :159.0 Min. :0
1st Qu.:13.00 1st Qu.:122.0 1st Qu.: 61.00 1st Qu.:183.0 1st Qu.:0
Median :41.00 Median :154.0 Median : 91.00 Median :208.0 Median :0
Mean :30.84 Mean :155.3 Mean : 88.98 Mean :232.1 Mean :0
3rd Qu.:45.00 3rd Qu.:190.0 3rd Qu.:119.00 3rd Qu.:255.0 3rd Qu.:0
Max. :53.00 Max. :331.0 Max. :226.00 Max. :690.0 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.000 Min. :27.82 Min. :-17.889 Min. : 1.0
1st Qu.: 0.000 1st Qu.:40.78 1st Qu.: -7.456 1st Qu.: 44.0
Median : 0.000 Median :42.08 Median : -1.787 Median : 251.0
Mean : 2.375 Mean :40.91 Mean : -2.938 Mean : 416.9
3rd Qu.: 0.000 3rd Qu.:42.64 3rd Qu.: 1.331 3rd Qu.: 445.0
Max. :685.000 Max. :43.57 Max. : 4.216 Max. :2535.0
if (!empty_nodes) {
df.clusters.dim <- c(dim(df.cluster01)[1], dim(df.cluster02)[1], dim(df.cluster03)[1], dim(df.cluster04)[1], dim(df.cluster05)[1])
barplot(df.clusters.dim,
names.arg = c("cluster01", "cluster02", "cluster03", "cluster04", "cluster05"),
col = "steelblue1")
}
if (!empty_nodes) mpr.hist(df.cluster01)
if (!empty_nodes) mpr.hist(df.cluster02)
if (!empty_nodes) mpr.hist(df.cluster03)
if (!empty_nodes) mpr.hist(df.cluster04)
if (!empty_nodes) mpr.hist(df.cluster05)
if (!empty_nodes) mpr.boxplot(df.cluster01)
if (!empty_nodes) mpr.boxplot(df.cluster02)
if (!empty_nodes) mpr.boxplot(df.cluster03)
if (!empty_nodes) mpr.boxplot(df.cluster04)
if (!empty_nodes) mpr.boxplot(df.cluster05)
# Agrupa por longitud y latitud para rellenar el mapa con menos datos.
if (!empty_nodes) {
df.cluster01.grouped <- mpr.group_by_geo(df.cluster01)
df.cluster02.grouped <- mpr.group_by_geo(df.cluster02)
df.cluster03.grouped <- mpr.group_by_geo(df.cluster03)
df.cluster04.grouped <- mpr.group_by_geo(df.cluster04)
df.cluster05.grouped <- mpr.group_by_geo(df.cluster05)
}
if (!empty_nodes) mpr.draw_map(spain, df.cluster01.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster02.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster03.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster04.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster05.grouped)
if (!empty_nodes) {
plot(hac, hang=-1, labels=F)
rect.hclust(hac, k=6)
}
A quĂ© clĂºster pertenece cada nodo del mapa de kohonen:
if (!empty_nodes) {
groups <- cutree(hac, k=6)
plot(model, type="mapping",
bgcol=c("steelblue1","sienna1","yellowgreen","red","blue","yellow","purple","green","white","#1f77b4", '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2')[groups],
shape = "straight", labels = "")
add.cluster.boundaries(model, clustering=groups)
}
if (!empty_nodes) {
# Asignamos a cada registro su clĂºster
df$cluster <- groups[model$unit.classif]
}
Nuevos dataframes por cluster
if (!empty_nodes) {
# Creo nuevos dataframes, uno por cada clĂºster.
df.cluster01 <- subset(df, cluster==1)
df.cluster02 <- subset(df, cluster==2)
df.cluster03 <- subset(df, cluster==3)
df.cluster04 <- subset(df, cluster==4)
df.cluster05 <- subset(df, cluster==5)
df.cluster06 <- subset(df, cluster==6)
# Extraigo del dataframe las features.
df.cluster01 <- select(df.cluster01, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster02 <- select(df.cluster02, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster03 <- select(df.cluster03, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster04 <- select(df.cluster04, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster05 <- select(df.cluster05, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster06 <- select(df.cluster06, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
}
if (!empty_nodes) summary(df.cluster01)
fecha_cnt tmax tmin precip nevada
Min. : 1.00 Min. : -3.0 Min. :-51.0 Min. : 0.000 Min. :0
1st Qu.:13.00 1st Qu.:211.0 1st Qu.:149.0 1st Qu.: 0.000 1st Qu.:0
Median :26.00 Median :234.0 Median :172.0 Median : 0.000 Median :0
Mean :26.29 Mean :229.6 Mean :165.2 Mean : 5.422 Mean :0
3rd Qu.:39.00 3rd Qu.:262.0 3rd Qu.:201.0 3rd Qu.: 2.000 3rd Qu.:0
Max. :53.00 Max. :384.0 Max. :263.0 Max. :167.000 Max. :0
prof_nieve longitud latitud altitud
Min. :0 Min. :27.82 Min. :-17.89 Min. : 14.0
1st Qu.:0 1st Qu.:28.05 1st Qu.:-16.56 1st Qu.: 25.0
Median :0 Median :28.44 Median :-16.33 Median : 33.0
Mean :0 Mean :28.35 Mean :-16.03 Mean : 369.5
3rd Qu.:0 3rd Qu.:28.48 3rd Qu.:-15.39 3rd Qu.: 64.0
Max. :0 Max. :28.95 Max. :-13.60 Max. :2371.0
if (!empty_nodes) summary(df.cluster02)
fecha_cnt tmax tmin precip nevada
Min. : 1.00 Min. :-22.0 Min. :-161.00 Min. : 0.00 Min. :0
1st Qu.: 7.00 1st Qu.:141.0 1st Qu.: 34.00 1st Qu.: 0.00 1st Qu.:0
Median :13.00 Median :178.0 Median : 71.00 Median : 5.00 Median :0
Mean :14.11 Mean :178.6 Mean : 67.74 Mean :10.95 Mean :0
3rd Qu.:19.00 3rd Qu.:219.0 3rd Qu.: 103.00 3rd Qu.:17.00 3rd Qu.:0
Max. :47.00 Max. :336.0 Max. : 195.00 Max. :79.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :35.28 Min. :-8.624 Min. : 1.0
1st Qu.: 0.00000 1st Qu.:40.07 1st Qu.:-3.919 1st Qu.: 69.0
Median : 0.00000 Median :41.32 Median :-1.117 Median : 370.0
Mean : 0.09987 Mean :40.83 Mean :-1.432 Mean : 447.3
3rd Qu.: 0.00000 3rd Qu.:42.11 3rd Qu.: 1.384 3rd Qu.: 779.0
Max. :299.00000 Max. :43.57 Max. : 4.216 Max. :2143.0
if (!empty_nodes) summary(df.cluster03)
fecha_cnt tmax tmin precip
Min. : 1.00 Min. :-109.00 Min. :-189.000 Min. : 0.00
1st Qu.:13.00 1st Qu.: 26.00 1st Qu.: -36.000 1st Qu.: 4.00
Median :26.00 Median : 70.00 Median : 5.000 Median : 21.00
Mean :26.51 Mean : 74.19 Mean : 6.032 Mean : 33.88
3rd Qu.:41.00 3rd Qu.: 124.00 3rd Qu.: 52.000 3rd Qu.: 49.00
Max. :53.00 Max. : 232.00 Max. : 148.000 Max. :256.00
nevada prof_nieve longitud latitud
Min. :0 Min. : 0.000 Min. :28.31 Min. :-16.4992
1st Qu.:0 1st Qu.: 0.000 1st Qu.:42.18 1st Qu.: 0.7789
Median :0 Median : 0.000 Median :42.47 Median : 1.2717
Mean :0 Mean : 9.254 Mean :42.29 Mean : 0.8465
3rd Qu.:0 3rd Qu.: 0.000 3rd Qu.:42.64 3rd Qu.: 1.7150
Max. :0 Max. :1073.000 Max. :42.77 Max. : 2.4378
altitud
Min. : 953
1st Qu.:1971
Median :2247
Mean :2187
3rd Qu.:2400
Max. :2535
if (!empty_nodes) summary(df.cluster04)
fecha_cnt tmax tmin precip nevada
Min. :13.0 Min. :129.0 Min. : 27.0 Min. : 0.0 Min. :0
1st Qu.:27.0 1st Qu.:256.0 1st Qu.:140.0 1st Qu.: 0.0 1st Qu.:0
Median :32.0 Median :289.0 Median :166.0 Median : 0.0 Median :0
Mean :32.1 Mean :285.4 Mean :165.8 Mean : 5.2 Mean :0
3rd Qu.:37.0 3rd Qu.:316.0 3rd Qu.:192.0 3rd Qu.: 6.0 3rd Qu.:0
Max. :52.0 Max. :442.0 Max. :272.0 Max. :71.0 Max. :0
prof_nieve longitud latitud altitud
Min. :0.000000 Min. :35.28 Min. :-8.6239 Min. : 1.0
1st Qu.:0.000000 1st Qu.:38.95 1st Qu.:-5.3456 1st Qu.: 35.0
Median :0.000000 Median :41.10 Median :-1.8606 Median : 127.0
Mean :0.001355 Mean :40.48 Mean :-2.0703 Mean : 270.5
3rd Qu.:0.000000 3rd Qu.:41.99 3rd Qu.: 0.8856 3rd Qu.: 513.0
Max. :7.000000 Max. :43.57 Max. : 4.2156 Max. :1167.0
if (!empty_nodes) summary(df.cluster05)
fecha_cnt tmax tmin precip nevada
Min. : 1.00 Min. :-31 Min. :-155.00 Min. : 0.00 Min. :0
1st Qu.:41.00 1st Qu.:125 1st Qu.: 33.00 1st Qu.: 1.00 1st Qu.:0
Median :46.00 Median :158 Median : 66.00 Median : 19.00 Median :0
Mean :41.03 Mean :161 Mean : 67.71 Mean : 35.76 Mean :0
3rd Qu.:49.00 3rd Qu.:191 3rd Qu.: 100.00 3rd Qu.: 62.00 3rd Qu.:0
Max. :53.00 Max. :407 Max. : 247.00 Max. :172.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :28.46 Min. :-16.329 Min. : 1.0
1st Qu.: 0.00000 1st Qu.:40.30 1st Qu.: -4.049 1st Qu.: 61.0
Median : 0.00000 Median :41.48 Median : -1.229 Median : 287.0
Mean : 0.09131 Mean :40.91 Mean : -1.555 Mean : 382.3
3rd Qu.: 0.00000 3rd Qu.:42.23 3rd Qu.: 1.401 3rd Qu.: 639.0
Max. :290.00000 Max. :43.57 Max. : 4.216 Max. :1894.0
if (!empty_nodes) summary(df.cluster06)
fecha_cnt tmax tmin precip nevada
Min. : 1.00 Min. :-21.0 Min. :-68.00 Min. :159.0 Min. :0
1st Qu.:13.00 1st Qu.:122.0 1st Qu.: 61.00 1st Qu.:183.0 1st Qu.:0
Median :41.00 Median :154.0 Median : 91.00 Median :208.0 Median :0
Mean :30.84 Mean :155.3 Mean : 88.98 Mean :232.1 Mean :0
3rd Qu.:45.00 3rd Qu.:190.0 3rd Qu.:119.00 3rd Qu.:255.0 3rd Qu.:0
Max. :53.00 Max. :331.0 Max. :226.00 Max. :690.0 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.000 Min. :27.82 Min. :-17.889 Min. : 1.0
1st Qu.: 0.000 1st Qu.:40.78 1st Qu.: -7.456 1st Qu.: 44.0
Median : 0.000 Median :42.08 Median : -1.787 Median : 251.0
Mean : 2.375 Mean :40.91 Mean : -2.938 Mean : 416.9
3rd Qu.: 0.000 3rd Qu.:42.64 3rd Qu.: 1.331 3rd Qu.: 445.0
Max. :685.000 Max. :43.57 Max. : 4.216 Max. :2535.0
if (!empty_nodes) {
df.clusters.dim <- c(dim(df.cluster01)[1], dim(df.cluster02)[1], dim(df.cluster03)[1], dim(df.cluster04)[1], dim(df.cluster05)[1], dim(df.cluster06)[1])
barplot(df.clusters.dim,
names.arg = c("cluster01", "cluster02", "cluster03", "cluster04", "cluster05", "cluster06"),
col = "steelblue1")
}
if (!empty_nodes) mpr.hist(df.cluster01)
if (!empty_nodes) mpr.hist(df.cluster02)
if (!empty_nodes) mpr.hist(df.cluster03)
if (!empty_nodes) mpr.hist(df.cluster04)
if (!empty_nodes) mpr.hist(df.cluster05)
if (!empty_nodes) mpr.hist(df.cluster06)
if (!empty_nodes) mpr.boxplot(df.cluster01)
if (!empty_nodes) mpr.boxplot(df.cluster02)
if (!empty_nodes) mpr.boxplot(df.cluster03)
if (!empty_nodes) mpr.boxplot(df.cluster04)
if (!empty_nodes) mpr.boxplot(df.cluster05)
if (!empty_nodes) mpr.boxplot(df.cluster06)
# Agrupa por longitud y latitud para rellenar el mapa con menos datos.
if (!empty_nodes) {
df.cluster01.grouped <- mpr.group_by_geo(df.cluster01)
df.cluster02.grouped <- mpr.group_by_geo(df.cluster02)
df.cluster03.grouped <- mpr.group_by_geo(df.cluster03)
df.cluster04.grouped <- mpr.group_by_geo(df.cluster04)
df.cluster05.grouped <- mpr.group_by_geo(df.cluster05)
df.cluster06.grouped <- mpr.group_by_geo(df.cluster06)
}
if (!empty_nodes) mpr.draw_map(spain, df.cluster01.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster02.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster03.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster04.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster05.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster06.grouped)
if (!empty_nodes) {
plot(hac, hang=-1, labels=F)
rect.hclust(hac, k=8)
}
A quĂ© clĂºster pertenece cada nodo del mapa de kohonen:
if (!empty_nodes) {
groups <- cutree(hac, k=8)
plot(model, type="mapping",
bgcol=c("steelblue1","sienna1","yellowgreen","red","blue","yellow","purple","green","white","#1f77b4", '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2')[groups],
shape = "straight", labels = "")
add.cluster.boundaries(model, clustering=groups)
}
if (!empty_nodes) {
# Asignamos a cada registro su clĂºster
df$cluster <- groups[model$unit.classif]
}
Nuevos dataframes por cluster
if (!empty_nodes) {
# Creo nuevos dataframes, uno por cada clĂºster.
df.cluster01 <- subset(df, cluster==1)
df.cluster02 <- subset(df, cluster==2)
df.cluster03 <- subset(df, cluster==3)
df.cluster04 <- subset(df, cluster==4)
df.cluster05 <- subset(df, cluster==5)
df.cluster06 <- subset(df, cluster==6)
df.cluster07 <- subset(df, cluster==7)
df.cluster08 <- subset(df, cluster==8)
# Extraigo del dataframe las features.
df.cluster01 <- select(df.cluster01, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster02 <- select(df.cluster02, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster03 <- select(df.cluster03, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster04 <- select(df.cluster04, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster05 <- select(df.cluster05, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster06 <- select(df.cluster06, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster07 <- select(df.cluster07, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster08 <- select(df.cluster08, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
}
if (!empty_nodes) summary(df.cluster01)
fecha_cnt tmax tmin precip nevada
Min. : 1.00 Min. : -3.0 Min. :-51.00 Min. : 0.000 Min. :0
1st Qu.:13.75 1st Qu.:101.0 1st Qu.: 28.00 1st Qu.: 0.000 1st Qu.:0
Median :26.00 Median :140.0 Median : 61.00 Median : 0.000 Median :0
Mean :26.39 Mean :144.7 Mean : 68.33 Mean : 7.374 Mean :0
3rd Qu.:39.00 3rd Qu.:191.0 3rd Qu.:109.00 3rd Qu.: 3.000 3rd Qu.:0
Max. :53.00 Max. :263.0 Max. :184.00 Max. :165.000 Max. :0
prof_nieve longitud latitud altitud
Min. :0 Min. :28.31 Min. :-16.5 Min. :2371
1st Qu.:0 1st Qu.:28.31 1st Qu.:-16.5 1st Qu.:2371
Median :0 Median :28.31 Median :-16.5 Median :2371
Mean :0 Mean :28.31 Mean :-16.5 Mean :2371
3rd Qu.:0 3rd Qu.:28.31 3rd Qu.:-16.5 3rd Qu.:2371
Max. :0 Max. :28.31 Max. :-16.5 Max. :2371
if (!empty_nodes) summary(df.cluster02)
fecha_cnt tmax tmin precip nevada
Min. : 1.00 Min. :-22.0 Min. :-161.00 Min. : 0.00 Min. :0
1st Qu.: 7.00 1st Qu.:141.0 1st Qu.: 34.00 1st Qu.: 0.00 1st Qu.:0
Median :13.00 Median :178.0 Median : 71.00 Median : 5.00 Median :0
Mean :14.11 Mean :178.6 Mean : 67.74 Mean :10.95 Mean :0
3rd Qu.:19.00 3rd Qu.:219.0 3rd Qu.: 103.00 3rd Qu.:17.00 3rd Qu.:0
Max. :47.00 Max. :336.0 Max. : 195.00 Max. :79.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :35.28 Min. :-8.624 Min. : 1.0
1st Qu.: 0.00000 1st Qu.:40.07 1st Qu.:-3.919 1st Qu.: 69.0
Median : 0.00000 Median :41.32 Median :-1.117 Median : 370.0
Mean : 0.09987 Mean :40.83 Mean :-1.432 Mean : 447.3
3rd Qu.: 0.00000 3rd Qu.:42.11 3rd Qu.: 1.384 3rd Qu.: 779.0
Max. :299.00000 Max. :43.57 Max. : 4.216 Max. :2143.0
if (!empty_nodes) summary(df.cluster03)
fecha_cnt tmax tmin precip
Min. : 1.00 Min. :-109.00 Min. :-189.000 Min. : 0.00
1st Qu.:13.00 1st Qu.: 26.00 1st Qu.: -36.000 1st Qu.: 4.00
Median :26.00 Median : 70.00 Median : 5.000 Median : 21.00
Mean :26.51 Mean : 74.19 Mean : 6.032 Mean : 33.88
3rd Qu.:41.00 3rd Qu.: 124.00 3rd Qu.: 52.000 3rd Qu.: 49.00
Max. :53.00 Max. : 232.00 Max. : 148.000 Max. :256.00
nevada prof_nieve longitud latitud
Min. :0 Min. : 0.000 Min. :28.31 Min. :-16.4992
1st Qu.:0 1st Qu.: 0.000 1st Qu.:42.18 1st Qu.: 0.7789
Median :0 Median : 0.000 Median :42.47 Median : 1.2717
Mean :0 Mean : 9.254 Mean :42.29 Mean : 0.8465
3rd Qu.:0 3rd Qu.: 0.000 3rd Qu.:42.64 3rd Qu.: 1.7150
Max. :0 Max. :1073.000 Max. :42.77 Max. : 2.4378
altitud
Min. : 953
1st Qu.:1971
Median :2247
Mean :2187
3rd Qu.:2400
Max. :2535
if (!empty_nodes) summary(df.cluster04)
fecha_cnt tmax tmin precip nevada
Min. : 1.00 Min. :126.0 Min. : 67.0 Min. : 0.000 Min. :0
1st Qu.:13.00 1st Qu.:218.0 1st Qu.:157.0 1st Qu.: 0.000 1st Qu.:0
Median :26.00 Median :239.0 Median :177.0 Median : 0.000 Median :0
Mean :26.28 Mean :240.6 Mean :177.8 Mean : 5.168 Mean :0
3rd Qu.:39.00 3rd Qu.:265.0 3rd Qu.:205.0 3rd Qu.: 2.000 3rd Qu.:0
Max. :53.00 Max. :384.0 Max. :263.0 Max. :167.000 Max. :0
prof_nieve longitud latitud altitud
Min. :0 Min. :27.82 Min. :-17.89 Min. : 14
1st Qu.:0 1st Qu.:28.05 1st Qu.:-17.75 1st Qu.: 25
Median :0 Median :28.46 Median :-16.33 Median : 33
Mean :0 Mean :28.36 Mean :-15.97 Mean :110
3rd Qu.:0 3rd Qu.:28.63 3rd Qu.:-13.86 3rd Qu.: 64
Max. :0 Max. :28.95 Max. :-13.60 Max. :632
if (!empty_nodes) summary(df.cluster05)
fecha_cnt tmax tmin precip nevada
Min. :13.0 Min. :129.0 Min. : 27.0 Min. : 0.0 Min. :0
1st Qu.:27.0 1st Qu.:256.0 1st Qu.:140.0 1st Qu.: 0.0 1st Qu.:0
Median :32.0 Median :289.0 Median :166.0 Median : 0.0 Median :0
Mean :32.1 Mean :285.4 Mean :165.8 Mean : 5.2 Mean :0
3rd Qu.:37.0 3rd Qu.:316.0 3rd Qu.:192.0 3rd Qu.: 6.0 3rd Qu.:0
Max. :52.0 Max. :442.0 Max. :272.0 Max. :71.0 Max. :0
prof_nieve longitud latitud altitud
Min. :0.000000 Min. :35.28 Min. :-8.6239 Min. : 1.0
1st Qu.:0.000000 1st Qu.:38.95 1st Qu.:-5.3456 1st Qu.: 35.0
Median :0.000000 Median :41.10 Median :-1.8606 Median : 127.0
Mean :0.001355 Mean :40.48 Mean :-2.0703 Mean : 270.5
3rd Qu.:0.000000 3rd Qu.:41.99 3rd Qu.: 0.8856 3rd Qu.: 513.0
Max. :7.000000 Max. :43.57 Max. : 4.2156 Max. :1167.0
if (!empty_nodes) summary(df.cluster06)
fecha_cnt tmax tmin precip nevada
Min. : 1.00 Min. : 29.0 Min. :-36.0 Min. : 26.00 Min. :0
1st Qu.:15.00 1st Qu.:143.0 1st Qu.: 67.0 1st Qu.: 59.00 1st Qu.:0
Median :29.00 Median :181.0 Median : 99.0 Median : 76.00 Median :0
Mean :28.23 Mean :187.2 Mean :100.4 Mean : 81.74 Mean :0
3rd Qu.:42.00 3rd Qu.:229.0 3rd Qu.:134.0 3rd Qu.: 99.00 3rd Qu.:0
Max. :53.00 Max. :407.0 Max. :247.0 Max. :172.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.000 Min. :28.46 Min. :-16.329 Min. : 1.0
1st Qu.: 0.000 1st Qu.:40.95 1st Qu.: -4.049 1st Qu.: 52.0
Median : 0.000 Median :41.84 Median : -1.033 Median : 251.0
Mean : 0.113 Mean :41.46 Mean : -1.568 Mean : 323.1
3rd Qu.: 0.000 3rd Qu.:42.70 3rd Qu.: 1.768 3rd Qu.: 515.0
Max. :73.000 Max. :43.57 Max. : 4.216 Max. :1894.0
if (!empty_nodes) summary(df.cluster07)
fecha_cnt tmax tmin precip nevada
Min. : 1.00 Min. :-21.0 Min. :-68.00 Min. :159.0 Min. :0
1st Qu.:13.00 1st Qu.:122.0 1st Qu.: 61.00 1st Qu.:183.0 1st Qu.:0
Median :41.00 Median :154.0 Median : 91.00 Median :208.0 Median :0
Mean :30.84 Mean :155.3 Mean : 88.98 Mean :232.1 Mean :0
3rd Qu.:45.00 3rd Qu.:190.0 3rd Qu.:119.00 3rd Qu.:255.0 3rd Qu.:0
Max. :53.00 Max. :331.0 Max. :226.00 Max. :690.0 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.000 Min. :27.82 Min. :-17.889 Min. : 1.0
1st Qu.: 0.000 1st Qu.:40.78 1st Qu.: -7.456 1st Qu.: 44.0
Median : 0.000 Median :42.08 Median : -1.787 Median : 251.0
Mean : 2.375 Mean :40.91 Mean : -2.938 Mean : 416.9
3rd Qu.: 0.000 3rd Qu.:42.64 3rd Qu.: 1.331 3rd Qu.: 445.0
Max. :685.000 Max. :43.57 Max. : 4.216 Max. :2535.0
if (!empty_nodes) summary(df.cluster08)
fecha_cnt tmax tmin precip nevada
Min. :31.00 Min. :-31 Min. :-155.00 Min. : 0.00 Min. :0
1st Qu.:46.00 1st Qu.:117 1st Qu.: 21.00 1st Qu.: 0.00 1st Qu.:0
Median :48.00 Median :149 Median : 51.00 Median : 3.00 Median :0
Mean :47.84 Mean :147 Mean : 50.32 Mean :11.26 Mean :0
3rd Qu.:50.00 3rd Qu.:177 3rd Qu.: 80.00 3rd Qu.:18.00 3rd Qu.:0
Max. :53.00 Max. :297 Max. : 189.00 Max. :76.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :35.28 Min. :-8.624 Min. : 1.0
1st Qu.: 0.00000 1st Qu.:39.49 1st Qu.:-4.049 1st Qu.: 69.0
Median : 0.00000 Median :41.19 Median :-1.293 Median : 359.0
Mean : 0.07977 Mean :40.61 Mean :-1.549 Mean : 413.9
3rd Qu.: 0.00000 3rd Qu.:41.98 3rd Qu.: 1.331 3rd Qu.: 687.0
Max. :290.00000 Max. :43.57 Max. : 4.216 Max. :1572.0
if (!empty_nodes) {
df.clusters.dim <- c(dim(df.cluster01)[1], dim(df.cluster02)[1], dim(df.cluster03)[1], dim(df.cluster04)[1], dim(df.cluster05)[1], dim(df.cluster06)[1], dim(df.cluster07)[1], dim(df.cluster08)[1])
barplot(df.clusters.dim,
names.arg = c("cluster01", "cluster02", "cluster03", "cluster04", "cluster05", "cluster06", "cluster07", "cluster08"),
col = "steelblue1")
}
if (!empty_nodes) mpr.hist(df.cluster01)
if (!empty_nodes) mpr.hist(df.cluster02)
if (!empty_nodes) mpr.hist(df.cluster03)
if (!empty_nodes) mpr.hist(df.cluster04)
if (!empty_nodes) mpr.hist(df.cluster05)
if (!empty_nodes) mpr.hist(df.cluster06)
if (!empty_nodes) mpr.hist(df.cluster07)
if (!empty_nodes) mpr.hist(df.cluster08)
if (!empty_nodes) mpr.boxplot(df.cluster01)
if (!empty_nodes) mpr.boxplot(df.cluster02)
if (!empty_nodes) mpr.boxplot(df.cluster03)
if (!empty_nodes) mpr.boxplot(df.cluster04)
if (!empty_nodes) mpr.boxplot(df.cluster05)
if (!empty_nodes) mpr.boxplot(df.cluster06)
if (!empty_nodes) mpr.boxplot(df.cluster07)
if (!empty_nodes) mpr.boxplot(df.cluster08)
# Agrupa por longitud y latitud para rellenar el mapa con menos datos.
if (!empty_nodes) {
df.cluster01.grouped <- mpr.group_by_geo(df.cluster01)
df.cluster02.grouped <- mpr.group_by_geo(df.cluster02)
df.cluster03.grouped <- mpr.group_by_geo(df.cluster03)
df.cluster04.grouped <- mpr.group_by_geo(df.cluster04)
df.cluster05.grouped <- mpr.group_by_geo(df.cluster05)
df.cluster06.grouped <- mpr.group_by_geo(df.cluster06)
df.cluster07.grouped <- mpr.group_by_geo(df.cluster07)
df.cluster08.grouped <- mpr.group_by_geo(df.cluster08)
}
if (!empty_nodes) mpr.draw_map(spain, df.cluster01.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster02.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster03.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster04.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster05.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster06.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster07.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster08.grouped)
if (!empty_nodes) {
plot(hac, hang=-1, labels=F)
rect.hclust(hac, k=10)
}
A quĂ© clĂºster pertenece cada nodo del mapa de kohonen:
if (!empty_nodes) {
groups <- cutree(hac, k=10)
plot(model, type="mapping",
bgcol=c("steelblue1","sienna1","yellowgreen","red","blue","yellow","purple","green","white","#1f77b4", '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2')[groups],
shape = "straight", labels = "")
add.cluster.boundaries(model, clustering=groups)
}
if (!empty_nodes) {
# Asignamos a cada registro su clĂºster
df$cluster <- groups[model$unit.classif]
}
Nuevos dataframes por cluster
if (!empty_nodes) {
# Creo nuevos dataframes, uno por cada clĂºster.
df.cluster01 <- subset(df, cluster==1)
df.cluster02 <- subset(df, cluster==2)
df.cluster03 <- subset(df, cluster==3)
df.cluster04 <- subset(df, cluster==4)
df.cluster05 <- subset(df, cluster==5)
df.cluster06 <- subset(df, cluster==6)
df.cluster07 <- subset(df, cluster==7)
df.cluster08 <- subset(df, cluster==8)
df.cluster09 <- subset(df, cluster==9)
df.cluster10 <- subset(df, cluster==10)
# Extraigo del dataframe las features.
df.cluster01 <- select(df.cluster01, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster02 <- select(df.cluster02, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster03 <- select(df.cluster03, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster04 <- select(df.cluster04, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster05 <- select(df.cluster05, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster06 <- select(df.cluster06, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster07 <- select(df.cluster07, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster08 <- select(df.cluster08, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster09 <- select(df.cluster09, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster10 <- select(df.cluster10, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
}
if (!empty_nodes) summary(df.cluster01)
fecha_cnt tmax tmin precip nevada
Min. : 1.00 Min. : -3.0 Min. :-51.00 Min. : 0.000 Min. :0
1st Qu.:13.75 1st Qu.:101.0 1st Qu.: 28.00 1st Qu.: 0.000 1st Qu.:0
Median :26.00 Median :140.0 Median : 61.00 Median : 0.000 Median :0
Mean :26.39 Mean :144.7 Mean : 68.33 Mean : 7.374 Mean :0
3rd Qu.:39.00 3rd Qu.:191.0 3rd Qu.:109.00 3rd Qu.: 3.000 3rd Qu.:0
Max. :53.00 Max. :263.0 Max. :184.00 Max. :165.000 Max. :0
prof_nieve longitud latitud altitud
Min. :0 Min. :28.31 Min. :-16.5 Min. :2371
1st Qu.:0 1st Qu.:28.31 1st Qu.:-16.5 1st Qu.:2371
Median :0 Median :28.31 Median :-16.5 Median :2371
Mean :0 Mean :28.31 Mean :-16.5 Mean :2371
3rd Qu.:0 3rd Qu.:28.31 3rd Qu.:-16.5 3rd Qu.:2371
Max. :0 Max. :28.31 Max. :-16.5 Max. :2371
if (!empty_nodes) summary(df.cluster02)
fecha_cnt tmax tmin precip nevada
Min. : 1.00 Min. : 66.0 Min. :-28.00 Min. : 0.00 Min. :0
1st Qu.: 9.00 1st Qu.:167.0 1st Qu.: 61.00 1st Qu.: 0.00 1st Qu.:0
Median :15.00 Median :196.0 Median : 86.00 Median : 4.00 Median :0
Mean :16.43 Mean :198.9 Mean : 86.47 Mean :10.87 Mean :0
3rd Qu.:21.00 3rd Qu.:230.0 3rd Qu.:112.00 3rd Qu.:17.00 3rd Qu.:0
Max. :47.00 Max. :336.0 Max. :195.00 Max. :73.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :35.28 Min. :-8.624 Min. : 1.0
1st Qu.: 0.00000 1st Qu.:39.49 1st Qu.:-4.010 1st Qu.: 43.0
Median : 0.00000 Median :41.22 Median :-0.558 Median : 185.0
Mean : 0.03217 Mean :40.68 Mean :-1.396 Mean : 370.9
3rd Qu.: 0.00000 3rd Qu.:42.08 3rd Qu.: 1.418 3rd Qu.: 674.0
Max. :173.00000 Max. :43.57 Max. : 4.216 Max. :2143.0
if (!empty_nodes) summary(df.cluster03)
fecha_cnt tmax tmin precip
Min. : 1.000 Min. :-22.0 Min. :-161.000 Min. : 0.00
1st Qu.: 3.000 1st Qu.: 92.0 1st Qu.: -11.000 1st Qu.: 0.00
Median : 6.000 Median :115.0 Median : 9.000 Median : 5.00
Mean : 6.527 Mean :112.5 Mean : 6.714 Mean :11.21
3rd Qu.: 9.000 3rd Qu.:135.0 3rd Qu.: 27.000 3rd Qu.:17.00
Max. :28.000 Max. :217.0 Max. : 89.000 Max. :79.00
nevada prof_nieve longitud latitud
Min. :0 Min. : 0.0000 Min. :36.64 Min. :-8.624
1st Qu.:0 1st Qu.: 0.0000 1st Qu.:40.66 1st Qu.:-3.789
Median :0 Median : 0.0000 Median :41.60 Median :-1.861
Mean :0 Mean : 0.3204 Mean :41.30 Mean :-1.549
3rd Qu.:0 3rd Qu.: 0.0000 3rd Qu.:42.11 3rd Qu.: 1.179
Max. :0 Max. :299.0000 Max. :43.36 Max. : 4.216
altitud
Min. : 1.0
1st Qu.: 515.0
Median : 687.0
Mean : 696.2
3rd Qu.: 890.0
Max. :1894.0
if (!empty_nodes) summary(df.cluster04)
fecha_cnt tmax tmin precip
Min. : 1.00 Min. :-109.00 Min. :-189.000 Min. : 0.00
1st Qu.:12.00 1st Qu.: 31.00 1st Qu.: -33.000 1st Qu.: 3.00
Median :26.00 Median : 76.00 Median : 8.000 Median :15.00
Mean :26.25 Mean : 78.97 Mean : 9.344 Mean :21.04
3rd Qu.:40.00 3rd Qu.: 131.00 3rd Qu.: 57.000 3rd Qu.:35.00
Max. :53.00 Max. : 232.00 Max. : 148.000 Max. :88.00
nevada prof_nieve longitud latitud altitud
Min. :0 Min. : 0.000 Min. :40.78 Min. :-4.0103 Min. :1002
1st Qu.:0 1st Qu.: 0.000 1st Qu.:42.29 1st Qu.: 0.7789 1st Qu.:1971
Median :0 Median : 0.000 Median :42.47 Median : 1.2717 Median :2247
Mean :0 Mean : 7.657 Mean :42.30 Mean : 0.8959 Mean :2189
3rd Qu.:0 3rd Qu.: 0.000 3rd Qu.:42.64 3rd Qu.: 1.7150 3rd Qu.:2400
Max. :0 Max. :985.000 Max. :42.77 Max. : 2.4378 Max. :2535
if (!empty_nodes) summary(df.cluster05)
fecha_cnt tmax tmin precip nevada
Min. : 1.00 Min. :126.0 Min. : 67.0 Min. : 0.000 Min. :0
1st Qu.:13.00 1st Qu.:218.0 1st Qu.:157.0 1st Qu.: 0.000 1st Qu.:0
Median :26.00 Median :239.0 Median :177.0 Median : 0.000 Median :0
Mean :26.28 Mean :240.6 Mean :177.8 Mean : 5.168 Mean :0
3rd Qu.:39.00 3rd Qu.:265.0 3rd Qu.:205.0 3rd Qu.: 2.000 3rd Qu.:0
Max. :53.00 Max. :384.0 Max. :263.0 Max. :167.000 Max. :0
prof_nieve longitud latitud altitud
Min. :0 Min. :27.82 Min. :-17.89 Min. : 14
1st Qu.:0 1st Qu.:28.05 1st Qu.:-17.75 1st Qu.: 25
Median :0 Median :28.46 Median :-16.33 Median : 33
Mean :0 Mean :28.36 Mean :-15.97 Mean :110
3rd Qu.:0 3rd Qu.:28.63 3rd Qu.:-13.86 3rd Qu.: 64
Max. :0 Max. :28.95 Max. :-13.60 Max. :632
if (!empty_nodes) summary(df.cluster06)
fecha_cnt tmax tmin precip nevada
Min. : 1.00 Min. :-69.00 Min. :-131.00 Min. : 47.0 Min. :0
1st Qu.:15.00 1st Qu.: 8.00 1st Qu.: -49.00 1st Qu.: 83.0 1st Qu.:0
Median :23.00 Median : 42.00 Median : -12.50 Median :102.0 Median :0
Mean :28.06 Mean : 45.84 Mean : -13.65 Mean :110.2 Mean :0
3rd Qu.:44.00 3rd Qu.: 82.00 3rd Qu.: 19.00 3rd Qu.:130.0 3rd Qu.:0
Max. :53.00 Max. :205.00 Max. : 115.00 Max. :256.0 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00 Min. :28.31 Min. :-16.4992 Min. : 953
1st Qu.: 0.00 1st Qu.:42.18 1st Qu.: 0.7789 1st Qu.:1971
Median : 0.00 Median :42.47 Median : 1.0544 Median :2247
Mean : 18.74 Mean :42.22 Mean : 0.5530 Mean :2171
3rd Qu.: 0.00 3rd Qu.:42.64 3rd Qu.: 1.5242 3rd Qu.:2400
Max. :1073.00 Max. :42.77 Max. : 2.4378 Max. :2535
if (!empty_nodes) summary(df.cluster07)
fecha_cnt tmax tmin precip nevada
Min. :13.0 Min. :129.0 Min. : 27.0 Min. : 0.0 Min. :0
1st Qu.:27.0 1st Qu.:256.0 1st Qu.:140.0 1st Qu.: 0.0 1st Qu.:0
Median :32.0 Median :289.0 Median :166.0 Median : 0.0 Median :0
Mean :32.1 Mean :285.4 Mean :165.8 Mean : 5.2 Mean :0
3rd Qu.:37.0 3rd Qu.:316.0 3rd Qu.:192.0 3rd Qu.: 6.0 3rd Qu.:0
Max. :52.0 Max. :442.0 Max. :272.0 Max. :71.0 Max. :0
prof_nieve longitud latitud altitud
Min. :0.000000 Min. :35.28 Min. :-8.6239 Min. : 1.0
1st Qu.:0.000000 1st Qu.:38.95 1st Qu.:-5.3456 1st Qu.: 35.0
Median :0.000000 Median :41.10 Median :-1.8606 Median : 127.0
Mean :0.001355 Mean :40.48 Mean :-2.0703 Mean : 270.5
3rd Qu.:0.000000 3rd Qu.:41.99 3rd Qu.: 0.8856 3rd Qu.: 513.0
Max. :7.000000 Max. :43.57 Max. : 4.2156 Max. :1167.0
if (!empty_nodes) summary(df.cluster08)
fecha_cnt tmax tmin precip nevada
Min. : 1.00 Min. : 29.0 Min. :-36.0 Min. : 26.00 Min. :0
1st Qu.:15.00 1st Qu.:143.0 1st Qu.: 67.0 1st Qu.: 59.00 1st Qu.:0
Median :29.00 Median :181.0 Median : 99.0 Median : 76.00 Median :0
Mean :28.23 Mean :187.2 Mean :100.4 Mean : 81.74 Mean :0
3rd Qu.:42.00 3rd Qu.:229.0 3rd Qu.:134.0 3rd Qu.: 99.00 3rd Qu.:0
Max. :53.00 Max. :407.0 Max. :247.0 Max. :172.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.000 Min. :28.46 Min. :-16.329 Min. : 1.0
1st Qu.: 0.000 1st Qu.:40.95 1st Qu.: -4.049 1st Qu.: 52.0
Median : 0.000 Median :41.84 Median : -1.033 Median : 251.0
Mean : 0.113 Mean :41.46 Mean : -1.568 Mean : 323.1
3rd Qu.: 0.000 3rd Qu.:42.70 3rd Qu.: 1.768 3rd Qu.: 515.0
Max. :73.000 Max. :43.57 Max. : 4.216 Max. :1894.0
if (!empty_nodes) summary(df.cluster09)
fecha_cnt tmax tmin precip nevada
Min. : 1.00 Min. :-21.0 Min. :-68.00 Min. :159.0 Min. :0
1st Qu.:13.00 1st Qu.:122.0 1st Qu.: 61.00 1st Qu.:183.0 1st Qu.:0
Median :41.00 Median :154.0 Median : 91.00 Median :208.0 Median :0
Mean :30.84 Mean :155.3 Mean : 88.98 Mean :232.1 Mean :0
3rd Qu.:45.00 3rd Qu.:190.0 3rd Qu.:119.00 3rd Qu.:255.0 3rd Qu.:0
Max. :53.00 Max. :331.0 Max. :226.00 Max. :690.0 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.000 Min. :27.82 Min. :-17.889 Min. : 1.0
1st Qu.: 0.000 1st Qu.:40.78 1st Qu.: -7.456 1st Qu.: 44.0
Median : 0.000 Median :42.08 Median : -1.787 Median : 251.0
Mean : 2.375 Mean :40.91 Mean : -2.938 Mean : 416.9
3rd Qu.: 0.000 3rd Qu.:42.64 3rd Qu.: 1.331 3rd Qu.: 445.0
Max. :685.000 Max. :43.57 Max. : 4.216 Max. :2535.0
if (!empty_nodes) summary(df.cluster10)
fecha_cnt tmax tmin precip nevada
Min. :31.00 Min. :-31 Min. :-155.00 Min. : 0.00 Min. :0
1st Qu.:46.00 1st Qu.:117 1st Qu.: 21.00 1st Qu.: 0.00 1st Qu.:0
Median :48.00 Median :149 Median : 51.00 Median : 3.00 Median :0
Mean :47.84 Mean :147 Mean : 50.32 Mean :11.26 Mean :0
3rd Qu.:50.00 3rd Qu.:177 3rd Qu.: 80.00 3rd Qu.:18.00 3rd Qu.:0
Max. :53.00 Max. :297 Max. : 189.00 Max. :76.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :35.28 Min. :-8.624 Min. : 1.0
1st Qu.: 0.00000 1st Qu.:39.49 1st Qu.:-4.049 1st Qu.: 69.0
Median : 0.00000 Median :41.19 Median :-1.293 Median : 359.0
Mean : 0.07977 Mean :40.61 Mean :-1.549 Mean : 413.9
3rd Qu.: 0.00000 3rd Qu.:41.98 3rd Qu.: 1.331 3rd Qu.: 687.0
Max. :290.00000 Max. :43.57 Max. : 4.216 Max. :1572.0
if (!empty_nodes) {
df.clusters.dim <- c(dim(df.cluster01)[1], dim(df.cluster02)[1], dim(df.cluster03)[1], dim(df.cluster04)[1], dim(df.cluster05)[1], dim(df.cluster06)[1], dim(df.cluster07)[1], dim(df.cluster08)[1], dim(df.cluster09)[1], dim(df.cluster10)[1])
barplot(df.clusters.dim,
names.arg = c("cluster01", "cluster02", "cluster03", "cluster04", "cluster05", "cluster06", "cluster07", "cluster08", "cluster09", "cluster10"),
col = "steelblue1")
}
if (!empty_nodes) mpr.hist(df.cluster01)
if (!empty_nodes) mpr.hist(df.cluster02)
if (!empty_nodes) mpr.hist(df.cluster03)
if (!empty_nodes) mpr.hist(df.cluster04)
if (!empty_nodes) mpr.hist(df.cluster05)
if (!empty_nodes) mpr.hist(df.cluster06)
if (!empty_nodes) mpr.hist(df.cluster07)
if (!empty_nodes) mpr.hist(df.cluster08)
if (!empty_nodes) mpr.hist(df.cluster09)
if (!empty_nodes) mpr.hist(df.cluster10)
if (!empty_nodes) mpr.boxplot(df.cluster01)
if (!empty_nodes) mpr.boxplot(df.cluster02)
if (!empty_nodes) mpr.boxplot(df.cluster03)
if (!empty_nodes) mpr.boxplot(df.cluster04)
if (!empty_nodes) mpr.boxplot(df.cluster05)
if (!empty_nodes) mpr.boxplot(df.cluster06)
if (!empty_nodes) mpr.boxplot(df.cluster07)
if (!empty_nodes) mpr.boxplot(df.cluster08)
if (!empty_nodes) mpr.boxplot(df.cluster09)
if (!empty_nodes) mpr.boxplot(df.cluster10)
# Agrupa por longitud y latitud para rellenar el mapa con menos datos.
if (!empty_nodes) {
df.cluster01.grouped <- mpr.group_by_geo(df.cluster01)
df.cluster02.grouped <- mpr.group_by_geo(df.cluster02)
df.cluster03.grouped <- mpr.group_by_geo(df.cluster03)
df.cluster04.grouped <- mpr.group_by_geo(df.cluster04)
df.cluster05.grouped <- mpr.group_by_geo(df.cluster05)
df.cluster06.grouped <- mpr.group_by_geo(df.cluster06)
df.cluster07.grouped <- mpr.group_by_geo(df.cluster07)
df.cluster08.grouped <- mpr.group_by_geo(df.cluster08)
df.cluster09.grouped <- mpr.group_by_geo(df.cluster09)
df.cluster10.grouped <- mpr.group_by_geo(df.cluster10)
}
if (!empty_nodes) mpr.draw_map(spain, df.cluster01.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster02.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster03.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster04.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster05.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster06.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster07.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster08.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster09.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster10.grouped)